package com.cxyd.modules.monitor.task;

import com.cxyd.common.utils.JsonUtils;
import com.cxyd.modules.monitor.server.WsSessionManager;
import com.cxyd.modules.wcs.dto.PlcItemDTO;
import com.cxyd.modules.wcs.service.PlcItemService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component("monitor-task")
public class MonitorTask {
    @Resource
    private PlcItemService plcItemService;

    public void broadcast() {
//        扫描相关视图,将数据提供给Client端
        List<PlcItemDTO> itemList = plcItemService.selectAll();
//        将数据转换为字符串格式
        String message = JsonUtils.toJsonString(itemList);
        WsSessionManager.broadcast(message);
    }
}
